import { game } from 'cc'
import BTAction from '../../Base/BTAction'
import { NodeStatus } from '../../Enum'

export default class ActionSleep extends BTAction {
  private duration: number = 2000
  private startTime: number = 0
  constructor(duration: number = 2000) {
    super()
    this.duration = duration
  }

  onStart() {
    super.onStart()
    this.startTime = game.totalTime
    console.log('ActionSleep onStart')
  }

  onUpdate() {
    if (game.totalTime - this.startTime > this.duration) {
      return NodeStatus.Success
    }

    return NodeStatus.Running
  }

  onEnd() {
    super.onEnd()
    console.log('ActionSleep onEnd')
  }
}
